<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>编辑文章</title>
    <%@ include file="/WEB-INF/commons/header.jsp" %>
    <link rel="stylesheet" href="${ctx}/static/layui/css/layui.css">
    <link rel="stylesheet" href="${ctx}/static/layui/css/bootstrap.min.css">

    <style type="text/css">
        .box{
            width: 240px;
            white-space: nowrap;             /*使文本内容不换行，写在一行*/
            overflow: hidden;                /*隐藏多余内容*/
            text-overflow: ellipsis;
        }
    </style>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <%@ include file="/WEB-INF/commons/navbar.jsp" %>
    <%@ include file="/WEB-INF/commons/menu.jsp" %>

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">

            <form action="${ctx}/news/queryNews">

                <div class="input-group">
                    <input type="text" name="keys" class="form-control" placeholder="请输入标题或作者...">
                    <span class="input-group-btn">
                            <button class="btn btn-default" type="submit">搜索</button>
                        </span>
                </div>

            </form>

            <table class="layui-table" lay-skin="line">
                <colgroup>
                    <col width="150">
                    <col width="100">
                    <col width="100">
                    <col width="200">
                    <col width="100">
                </colgroup>
                <thead>
                <tr>
                    <th bgcolor="#dae0e4" style="font-weight: bold;text-align: center">标题</th>
                    <th bgcolor="#dae0e4" style="font-weight: bold;text-align: center">作者</th>
                    <th bgcolor="#dae0e4" style="font-weight: bold;text-align: center">发布时间</th>
                    <th bgcolor="#dae0e4" style="font-weight: bold;text-align: center">内容</th>
                    <th bgcolor="#dae0e4" style="font-weight: bold;text-align: center">操作</th>
                </tr>
                </thead>
                <tbody>
               <c:forEach items="${newsList}" var="news">
                   <tr>
                       <td>${news.newsTitle}</td>
                       <td align="center">${news.newsAuthor}</td>
                       <td align="center">${news.createTime}</td>
                       <td align="center">
                           <div class="box">
                               <span><a href="${ctx}/news/showDetails?id=${news.id}">${news.newsArticle}</a></span>
                           </div>
                       </td>
                       <td align="center">
                           <div class="layui-btn-group">
                               <a href="${ctx}/news/reviseNews?id=${news.id}"><button type="button" class="layui-btn layui-btn-sm"
                                       onclick="return window.confirm('确定修改吗？') ">修改</button>
                               </a>

                              <a href="${ctx}/news/deleteNews?id=${news.id}"
                                 onclick="return window.confirm('请确认是否删除')?alert('删除成功'):alert('删除失败')">
                                  <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" >
                                   删除
                                  </button>
                              </a>

                           </div>
                       </td>
                   </tr>
               </c:forEach>

                </tbody>
            </table>
        </div>

        <div id="pageInfo" align="right"></div>

    </div>
</div>

<script src="${ctx}/static/layui/jquery-3.2.1.min.js"></script>
<script src="${ctx}/static/layui/layui.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">

    layui.config({
        base:${ctx}/
    }).use(['element', 'layer', 'jquery', 'laypage'], function () {
        var element = layui.element, layer = layui.layer, $ = layui.jquery, laypage = layui.laypage;
        laypage.render({
            elem: 'pageInfo'
            , count: ${count} //数据总数，从服务端得到
            , limits: [10, 20, 30]
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , curr: ${curr}
            , jump: function (obj, first) {

                //首次不执行
                if (!first) {
                    window.location.href = '${ctx}/news/showNews?start=' + obj.curr + '&size=' + obj.limit;
                }
            }
        });


    });


    <%--function deleteNews() {--%>
    <%--    $.ajax({--%>
    <%--        type:"GET",--%>
    <%--        url:"${ctx}/news/deleteNews",--%>
    <%--        data:{--%>
    <%--           "id": ${news.id}--%>
    <%--        },success:function (data) {--%>
    <%--            alert("删除成功");--%>
    <%--            window.location.reload();--%>
    <%--        }--%>
    <%--    })--%>
    <%--}--%>



</script>

</body>
</html>
